/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package registrofia;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.Statement;

/**
 *
 * @author anderson
 */
public class OracleConnection {
    
    public static Connection getConnection() throws Exception {
        String driver = "oracle.jdbc.OracleDriver";
        String url = "jdbc:oracle:thin:@localhost:1521:XE";
        String username = "testdatabase";
        String password = "1234567";
        Class.forName(driver); // load JDBC-ODBC driver
        return DriverManager.getConnection(url, username, password);
    }

    public static void main(String args[]) {
        Connection conn = null;
        Statement stmt = null;
        ResultSet rs = null;
        try {
            conn = getConnection();
            stmt = conn.createStatement();
            String query = "SELECT id_autor, nombre_autor FROM autor";
            rs = stmt.executeQuery(query);
            while (rs.next()) {
                System.out.println(rs.getString("id_autor") + " " + rs.getString("nombre_autor") + " "
                        + rs.getString("id_autor"));
            }
        } catch (Exception e) {
            // handle the exception
            e.printStackTrace();
            System.err.println(e.getMessage());
        } finally {
            try {
                rs.close();
                stmt.close();
                conn.close();
            } catch (Exception ee) {
                ee.printStackTrace();
            }
        }
    }
}